﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProduct" :model="stateProduct.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductCode_FormItem" prop="Entity.ProductCode" :label="$t('message.autotrans._Model_Product_ProductCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Product_ProductCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateProduct.vmModel.Entity.ProductCode" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_Product_ProductName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Product_ProductName')}), trigger: 'blur' }]" >
            <el-input v-model="stateProduct.vmModel.Entity.ProductName" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductVersion_FormItem" prop="Entity.ProductVersion" :label="$t('message.autotrans._Model_Product_ProductVersion')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Product_ProductVersion')}), trigger: 'blur' }]" >
            <el-input v-model="stateProduct.vmModel.Entity.ProductVersion" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Product_Type_FormItem" prop="Entity.Product_Type" :label="$t('message.autotrans._Model_Product_Product_Type')">
            <el-select v-model="stateProduct.vmModel.Entity.Product_Type" disabled clearable>
               <el-option key="PRODUCT" value="PRODUCT" :label="$t('message.autotrans._Enum_ProductType_PRODUCT')"></el-option>
               <el-option key="HALF_PRODUCT" value="HALF_PRODUCT" :label="$t('message.autotrans._Enum_ProductType_HALF_PRODUCT')"></el-option>
               <el-option key="OTHER" value="OTHER" :label="$t('message.autotrans._Enum_ProductType_OTHER')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IsVulnerable_FormItem" prop="Entity.IsVulnerable" :label="$t('message.autotrans._Model_Product_IsVulnerable')">
            <el-input v-model="stateProduct.vmModel.Entity.IsVulnerable" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductStatus_FormItem" prop="Entity.ProductStatus" :label="$t('速比')">
            <el-input v-model="stateProduct.vmModel.Entity.ProductStatus" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Notes_FormItem" prop="Entity.Notes" :label="$t('message.autotrans._Model_Product_Notes')">
            <el-input v-model="stateProduct.vmModel.Entity.Notes" disabled clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onCloseProduct"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationProductDetails;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { productApi } from '/@/api/baseinformation/product';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProduct = ref();
const stateProduct = reactive({
    vmModel: {
	  Entity:{
        ProductCode: '',
        ProductName: '',
        ProductVersion: '',
        Product_Type: undefined,
        IsVulnerable: undefined,
        ProductStatus: '',
        Notes: '',
        ID:null,
      },

	},
    
});

// 取消
const onCloseProduct = () => {
    closeDialog();
};

// 提交
const onSubmitProduct = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProduct.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            productApi().edit(stateProduct.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
	})
};

// 页面加载时
onMounted(() => {
    
    if (ci.attrs["wtmdata"]) {
		stateProduct.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProduct.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	productApi().get(stateProduct.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProduct.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

